package com.acxy.auth;

import com.acxy.ants.common.kit.PropKit;
import com.acxy.ants.core.config.AntsConfig;
import com.acxy.ants.core.config.Constants;
import com.acxy.ants.core.config.Handlers;
import com.acxy.ants.core.config.Plugins;
import com.acxy.ants.core.handler.LimitRefreshHandler;
import com.acxy.ants.core.handler.PathHandler;
import com.acxy.ants.core.plugin.db.DruidPlugin;
import com.acxy.auth.common.SysConst;
import com.acxy.auth.handler.AuthHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-04-26
 */
public class AppConfig extends AntsConfig {

    /**
     * 常量配置
     *
     * @param me
     */
    @Override
    public void configConstant(Constants me) {
        PropKit.use("resources.properties");
        me.setDebug(PropKit.getBoolean("debug"));
        me.setError404Page("/errors/404.html");
        me.setError500Page("/errors/500.html");
    }

    /**
     * 插件配置
     *
     * @param me
     */
    @Override
    public void configPlugin(Plugins me) {
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.getStr("url"), PropKit.getStr("driverClassName"), PropKit.getStr("username"), PropKit.getStr("password"));
        me.add(druidPlugin);
      //  me.add(new SqlMapPlugin("mapper", getModules()));

    }

    /**
     * handler请求链配置
     *
     * @param me
     */
    @Override
    public void configHandler(Handlers me) {
        //防止恶意刷新接口通过程序解决, 也可以通过配置web容器解决
        me.add(new LimitRefreshHandler(1000, "/"));
        Map<String, String> pathMap = new HashMap<>();
        pathMap.put("ctx", "");
        pathMap.put("JS_PATH", "/static/js");
        pathMap.put("IMG_PATH", "/static/images");
        pathMap.put("CSS_PATH", "/static/css");
        pathMap.put("SWF_PATH", "/static/swf");
        pathMap.put("UE_PATH", "/static/ueditor");
        AuthHandler authHandler = new AuthHandler(SysConst.USER_SESSION_NAME);
      //  me.add(authHandler);
        me.add(new PathHandler(pathMap));
    }
}
